package com.lagou.edu.api.impl;

import com.lagou.edu.api.CodeService;
import com.lagou.edu.common.RestResult;
import com.lagou.edu.service.AuthCodeService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class CodeServiceImpl implements CodeService {

    @Autowired
    private AuthCodeService authCodeService;

    @Override
    public RestResult validate(String email, String code) {
        int res = authCodeService.compareAuthCode(email, code); // 校验验证码. 0正确，1错误，2超时
        RestResult restResult = new RestResult();
        restResult.setStatus(res);
        switch (res) {
            case 0:
                restResult.setMessage("验证成功！");
                break;
            case 1:
                restResult.setMessage("验证失败！");
                break;
            case 2:
                restResult.setMessage("验证码超时，请重新发送验证码！");
                break;
        }

        return restResult;
    }
}
